﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Spectrum
{
    /// <summary>
    /// 单质点响应参数
    /// </summary>
    public class ResponseParam
    {
        /// <summary>
        /// 时刻
        /// </summary>
        public float Time { set; get; }

        /// <summary>
        /// 响应
        /// </summary>
        public float U { set; get; }

        /// <summary>
        /// 响应
        /// </summary>
        public float A { set; get; }

        /// <summary>
        /// 响应
        /// </summary>
        public float V { set; get; }

        /// <summary>
        /// 重载加号
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <returns></returns>
        public static ResponseParam operator +(ResponseParam i, ResponseParam j)
        {
            return new ResponseParam
            {
                Time = Math.Max(i.Time, j.Time),
                U = i.U + j.U,
                V = i.V + j.V,
                A = i.A + j.A,
            };
        }

        /// <summary>
        /// 重载乘号
        /// </summary>
        /// <param name="i"></param>
        /// <param name="factor"></param>
        /// <returns></returns>
        public static ResponseParam operator *(ResponseParam i, float factor)
        {
            return new ResponseParam
            {
                Time = i.Time,
                U = i.U * factor,
                V = i.V * factor,
                A = i.A * factor,
            };
        }

        /// <summary>
        /// 加速度及速度转为拟加速度
        /// </summary>
        /// <param name="wn"></param>
        public void ToPesudo(double wn)
        {
            this.A = (float)(this.U * Math.Pow(wn, 2));
            this.V = (float)(this.U * wn);
        }

        /// <summary>
        /// 响应放大
        /// </summary>
        /// <param name="factor"></param>
        public void Amplitude(float factor)
        {
            this.U *= factor;
            this.A *= factor;
            this.V *= factor;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ResponseParam()
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="time"></param>
        /// <param name="response"></param>
        public ResponseParam(float time, float u, float a, float v)
        {
            this.Time = time;
            this.U = u;
            this.A = a;
            this.V = v;
        }

        /// <summary>
        /// 平方和开方
        /// </summary>
        /// <param name="paramX"></param>
        /// <param name="paramY"></param>
        public ResponseParam(ResponseParam paramX, ResponseParam paramY)
        {
            this.Time = paramX.Time;
            this.U = (float)Math.Sqrt(Math.Pow(paramX.U, 2) + Math.Pow(paramY.U, 2));
            this.A = (float)Math.Sqrt(Math.Pow(paramX.A, 2) + Math.Pow(paramY.A, 2));
            this.V = (float)Math.Sqrt(Math.Pow(paramX.V, 2) + Math.Pow(paramY.V, 2));
        }
    }
}
